define([], function() {
	'use strict';
	var OnReady = {
		parseDataOptions : function () {
			var script = $('script[src="jl.js"]');
			script.length === 0 && (script = $('script[src$="../jl.js"]'));
			script.length === 0 && (script = $('script[src$="./jl.js"]'));
			var dataOptions = {};
			if (script.length) {
				try {
					var data = script.attr('data-options');
					data = data ? data : '{}';
					dataOptions = $.parseJSON(data);
				} catch (e) {
					console.error('Parse data options failed.');
				}
			} else {
				console.error('Can not find the jl.js');
			}
			jl.dataOptions = dataOptions;
		},
		loadJs : function () {
			var jsArray = [];
			if (jl.dataOptions.loadJs === false) {
				return;
			}else if (jl.dataOptions.loadJs === true) {
				var url = document.location.href;
				var pathname = document.location.pathname;
				var jsPath = pathname.replace('.html', '');
				if (url.indexOf('.html') === -1) {
					jsPath = jsPath.replace(/#+$/g, '');
					jsPath = jsPath + 'index';
				}
				jsPath = jsPath.replace(/^\/+/g, '');
				jsArray.push(jsPath);
			} else if (_.isArray(jl.dataOptions.loadJs) === true) {
				jsArray = jl.dataOptions.loadJs;
			} else {
				jsArray.push(jl.dataOptions.loadJs);
			}
			_.each(jsArray, function(jsFilePath) {
				require([ jsFilePath ]);
			});
		}
	};
	
	$(function(){
		OnReady.parseDataOptions();
		OnReady.loadJs();
	})
});
